<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var reachNumber = function (target) {
      target = Math.abs(target);
      let step = 0;
      // 找到使得1+2+3+...+k>target 的最小k
      let dis = 0

      while (dis < target || (dis - target & 1)) dis += ++step;
      return step
    };
    console.log(reachNumber(2));
  </script>
</body>

</html>